home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch12 / BounceWindow.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  4.4 KB  |  146 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. //////////////////////////////////////////////////////////
  22. // BounceWindow.C
  23. //////////////////////////////////////////////////////////
  24. #include "Application.h"
  25. #include "BounceWindow.h"
  26. #include "Stage.h"
  27. #include "ControlPanel.h"
  28. #include "BounceClock.h"
  29. #include "QuitCmd.h"
  30. #include "UndoCmd.h"
  31. #include "CmdList.h"
  32. #include "AddBallCmd.h"
  33. #include "MenuBar.h"
  34. #include <Xm/Form.h>
  35. #include <Xm/Separator.h>
  36.  
  37. BounceWindow::BounceWindow ( char *name ) : MenuWindow ( name )
  38. {
  39.     _clock         = NULL;
  40.     _stage         = NULL;
  41.     _controlPanel  = NULL;
  42. }
  43.  
  44. BounceWindow::~BounceWindow ()
  45. {
  46.     delete _clock;
  47.     delete _stage;
  48.     delete _controlPanel;
  49. }
  50.  
  51. Widget BounceWindow::createWorkArea ( Widget parent )
  52. {
  53.     // The BounceWindow work area is implemented as a 
  54.     // form widget that contains the other components
  55.     // of the bounce interface
  56.     
  57.     Widget form =  XtCreateWidget ( "workArea", 
  58.                    xmFormWidgetClass,
  59.                    parent,
  60.                    NULL, 0 );
  61.     
  62.     // Create each major component of the bounce window
  63.     
  64.     _stage        = new Stage ( form, "stage" );
  65.     _clock        = new BounceClock ( form, "clock", _stage );
  66.     _controlPanel = new ControlPanel ( form, "control", _clock );
  67.     
  68.     // Set up the attachments to achieve the layout shown in Figure 12.1
  69.     
  70.     XtVaSetValues ( _controlPanel->baseWidget(),
  71.            XmNtopWidget,        _clock->baseWidget(),
  72.            XmNtopAttachment,    XmATTACH_OPPOSITE_WIDGET,
  73.            XmNleftAttachment,   XmATTACH_FORM,
  74.            XmNrightPosition,    50,
  75.            XmNrightAttachment,  XmATTACH_POSITION,
  76.            XmNbottomAttachment, XmATTACH_NONE,
  77.            NULL );
  78.     
  79.     XtVaSetValues ( _clock->baseWidget(), 
  80.            XmNtopAttachment,    XmATTACH_NONE,
  81.            XmNleftPosition,     50,
  82.            XmNleftAttachment,   XmATTACH_POSITION,
  83.            XmNrightAttachment,  XmATTACH_FORM,
  84.            XmNbottomAttachment, XmATTACH_FORM,
  85.            NULL );
  86.     
  87.     Widget sep =  
  88.     XtVaCreateManagedWidget ( "sep", 
  89.                  xmSeparatorWidgetClass,
  90.                  form,
  91.                  XmNleftAttachment,   XmATTACH_FORM,
  92.                  XmNrightAttachment,  XmATTACH_FORM,
  93.                  XmNtopAttachment,    XmATTACH_NONE,
  94.                  XmNbottomWidget,     _clock->baseWidget(),
  95.                  XmNbottomAttachment, XmATTACH_WIDGET,
  96.                  NULL );
  97.     
  98.     
  99.     XtVaSetValues ( _stage->baseWidget(),
  100.            XmNtopAttachment,    XmATTACH_FORM,
  101.            XmNleftAttachment,   XmATTACH_FORM,
  102.            XmNrightAttachment,  XmATTACH_FORM,
  103.            XmNbottomWidget,     sep,
  104.            XmNbottomAttachment, XmATTACH_WIDGET,
  105.            NULL );
  106.     
  107.     // Manage all the child widgets and return the form
  108.     
  109.     _controlPanel->manage();
  110.     _stage->manage();
  111.     _clock->manage();    
  112.     
  113.     return ( form );        
  114. }
  115.  
  116. void BounceWindow::createMenuPanes ()
  117. {
  118.     // Create the main application menu, with just a quit and undo cmd
  119.     
  120.     CmdList *cmdList  = new CmdList();
  121.     Cmd     *quit     = new QuitCmd ( "Quit", TRUE );
  122.     cmdList->add ( theUndoCmd );        
  123.     cmdList->add ( quit );
  124.     _menuBar->addCommands ( cmdList, "Application" );
  125.     
  126.     // Create a menu for adding actors to the screen
  127.     
  128.     CmdList *actorList = new CmdList();
  129.     
  130.     Cmd *addRed   = new AddBallCmd ( "Add Red Ball",   TRUE, 
  131.                     _stage,  "Red"  );
  132.     Cmd *addGreen = new AddBallCmd ( "Add Green Ball", TRUE, 
  133.                     _stage, "Green" );
  134.     Cmd *addBlue  = new AddBallCmd ( "Add Blue Ball",  TRUE,
  135.                     _stage, "Blue"  ); 
  136.     Cmd *addAny   = new AddBallCmd ( "Add Ball...",    TRUE,
  137.                     _stage );    
  138.     
  139.     actorList->add ( addRed );
  140.     actorList->add ( addGreen );
  141.     actorList->add ( addBlue );
  142.     actorList->add ( addAny );
  143.     
  144.     _menuBar->addCommands ( actorList, "Actors" );
  145. }
  146.